"use client";

import ActivityMask from "@/components/ModalPopup/ActivityModal";
import { useRouter } from "@/i18n/routing";
import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";

const Page = () => {
    const searchParams = useSearchParams();
    const url = decodeURIComponent(`${searchParams}`);
    const router = useRouter();
    const handler = (event: MessageEvent) => {
        if (event.data === "closeMessage") {
            router.push("/");
        }
    };
    useEffect(() => {
        // @ts-ignore
        window.quit = () => {
            router.push("/");
        };

        window.addEventListener("message", handler);
        return () => window.removeEventListener("message", handler);
    }, []);

    // 关闭iframe弹窗
    const [categoryName, setCategoryName] = useState<string>("")
    useEffect(() => {
        const parmas: any = new URLSearchParams(url)
        setCategoryName(parmas.get('category_name'))
    }, [url]);
    const goBlack = () => {
        router.push("/")
    }
    return (
        <>
            <div style={{ width: "100%", height: "100%" }}>
                {/* 真人游戏添加关闭按钮 */}
                {
                    categoryName === "Live Casino Jogos" && <i 
                        className={"iconfont icon-guanbi"} 
                        style={{
                            position: 'fixed',
                            top: '0.1rem',
                            right: '0.1rem',
                            zIndex: "99999",
                            fontSize: '.2rem'
                        }} 
                        onClick={goBlack}
                    ></i>
                }
                <iframe src={url} width={"100%"} height={"100%"}></iframe>
            </div>

            {/* 数千补偿 */}
            <ActivityMask />
        </>
    );
};

export default Page;
